class Solution
{
public:
    int countNegatives(vector<vector<int>> &grid)
    {
        int m = grid.size();
        int n = grid[0].size();
        int result = 0;
        int row = 0;
        int col = n - 1;
        while (row < m && col >= 0)
        {
            if (grid[row][col] < 0)
            {
                result += m - row;
                --col;
            }
            else
            {
                ++row;
            }
        }
        return result;
    }
};